package cn.jhg.account.service;

import java.util.List;

import javax.annotation.Resource;

import org.bson.Document;
import org.bson.types.ObjectId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import cn.jhg.account.entity.ParamValue;
import cn.jhg.account.persist.PVDao;
import cn.jhg.account.util.ServiceResult;

@Service("pvSvc")
@Transactional
public class PVSvcImpl implements PVSvc {

	@Resource
	private PVDao pvDao;
	
	@Resource
	private MongoTemplate mongoTemplate;
	
	private Logger logger = LoggerFactory.getLogger(PVSvcImpl.class);
	
	@Override
	public ServiceResult<List<ParamValue>> findPVs(String param_name) {
		
		ServiceResult<List<ParamValue>> result = new ServiceResult<List<ParamValue>>();
		
		logger.info(param_name);
		
		try{
			List<ParamValue> data = pvDao.findPVs(param_name);
			
			for (ParamValue pv:data){
				Document doc = mongoTemplate.findById(new ObjectId("58d654443417d7421cec54bf"), Document.class, "pv_parameter");
				
				Object obj = doc.get("param");
				
				String str = obj.toString();
				
				
			}
			
			result.setData(data);
			result.setErrorCode(0);
		}
		catch (Exception e){
			result.setErrorCode(-1);
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
		
		return result;
		
	}

}
